package com.traffic.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.FamilyBasicInformation;
import com.traffic.service.IFamilyBasicInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户家属基础信息Controller
 * 
 * @author zzs
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/familyBasicInformation")
public class FamilyBasicInformationController extends BaseController
{
    @Autowired
    private IFamilyBasicInformationService familyBasicInformationService;

    /**
     * 查询用户家属基础信息列表
     */
    @RequiresPermissions("information:information:list")
    @GetMapping("/list")
    public TableDataInfo list(FamilyBasicInformation familyBasicInformation)
    {
        startPage();
        List<FamilyBasicInformation> list = familyBasicInformationService.selectFamilyBasicInformationList(familyBasicInformation);
        return getDataTable(list);
    }

    /**
     * 导出用户家属基础信息列表
     */
    @RequiresPermissions("information:information:export")
    @Log(title = "用户家属基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyBasicInformation familyBasicInformation)
    {
        List<FamilyBasicInformation> list = familyBasicInformationService.selectFamilyBasicInformationList(familyBasicInformation);
        ExcelUtil<FamilyBasicInformation> util = new ExcelUtil<FamilyBasicInformation>(FamilyBasicInformation.class);
        util.exportExcel(response, list, "用户家属基础信息数据");
    }

    /**
     * 获取用户家属基础信息详细信息
     */
    @RequiresPermissions("information:information:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familyBasicInformationService.selectFamilyBasicInformationById(id));
    }

    /**
     * 新增用户家属基础信息
     */
    @RequiresPermissions("information:information:add")
    @Log(title = "用户家属基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyBasicInformation familyBasicInformation)
    {
        return toAjax(familyBasicInformationService.insertFamilyBasicInformation(familyBasicInformation));
    }

    /**
     * 修改用户家属基础信息
     */
    @RequiresPermissions("information:information:edit")
    @Log(title = "用户家属基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyBasicInformation familyBasicInformation)
    {
        return toAjax(familyBasicInformationService.updateFamilyBasicInformation(familyBasicInformation));
    }

    /**
     * 删除用户家属基础信息
     */
    @RequiresPermissions("information:information:remove")
    @Log(title = "用户家属基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familyBasicInformationService.deleteFamilyBasicInformationByIds(ids));
    }
}
